package com.lzxuni.modules.disease.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lzxuni.common.utils.poi.ExcelUtil;
import com.lzxuni.modules.common.entity.PageParameter;
import com.lzxuni.modules.disease.entity.DiseaseManagement;
import com.lzxuni.modules.disease.mapper.DiseaseManagementMapper;
import com.lzxuni.modules.disease.service.DiseaseInformationService;
import com.lzxuni.modules.disease.service.DiseaseManagementService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lzxuni.modules.organization.entity.CustomerMember;
import com.lzxuni.modules.soilmoisture.entity.TblSoilMoisture;
import com.lzxuni.modules.weather.entity.WeatherInfo;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import com.lzxuni.common.utils.StringUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

/**
 * <p>
 * 病情管理 服务实现类
 * </p>
 *
 * @author gyl
 * @since 2020-12-02
 */
@Service
public class DiseaseManagementServiceImpl extends ServiceImpl<DiseaseManagementMapper, DiseaseManagement> implements DiseaseManagementService {

        @Override
        public PageInfo<DiseaseManagement> queryPage(PageParameter pageParameter, DiseaseManagement diseaseManagement) {
            if (StringUtils.isNotEmpty(pageParameter.getSidx())) {
                PageHelper.startPage(pageParameter.getPage(), pageParameter.getRows()).setOrderBy(
                pageParameter.getSidx() + " " + pageParameter.getSord());
            } else {
                PageHelper.startPage(pageParameter.getPage(), pageParameter.getRows());
            }
            List<DiseaseManagement> diseaseManagementList = baseMapper.queryList(diseaseManagement);
            PageInfo<DiseaseManagement> pageInfo = new PageInfo<>(diseaseManagementList);
            return pageInfo;
        }

          @Override
        public PageInfo<DiseaseManagement> queryPage2(PageParameter pageParameter, DiseaseManagement diseaseManagement) {
            if (StringUtils.isNotEmpty(pageParameter.getSidx())) {
                PageHelper.startPage(pageParameter.getPage(), pageParameter.getRows()).setOrderBy(
                pageParameter.getSidx() + " " + pageParameter.getSord());
            } else {
                PageHelper.startPage(pageParameter.getPage(), pageParameter.getRows());
            }
            List<DiseaseManagement> diseaseManagementList = baseMapper.queryDMList(diseaseManagement);
            PageInfo<DiseaseManagement> pageInfo = new PageInfo<>(diseaseManagementList);
            return pageInfo;
        }

           @Override
        public PageInfo<DiseaseManagement> queryPage3(PageParameter pageParameter, DiseaseManagement diseaseManagement) {
            if (StringUtils.isNotEmpty(pageParameter.getSidx())) {
                PageHelper.startPage(pageParameter.getPage(), pageParameter.getRows()).setOrderBy(
                pageParameter.getSidx() + " " + pageParameter.getSord());
            } else {
                PageHelper.startPage(pageParameter.getPage(), pageParameter.getRows());
            }
               List<DiseaseManagement> diseaseManagementList = baseMapper.queryGLList(diseaseManagement);
            PageInfo<DiseaseManagement> pageInfo = new PageInfo<>(diseaseManagementList);
            return pageInfo;
        }

        @Override
        public List<DiseaseManagement> queryList(DiseaseManagement diseaseManagement) {
            List<DiseaseManagement> diseaseManagementList = baseMapper.queryList(diseaseManagement);
            return diseaseManagementList;
        }

    @Override
    public Workbook exportExcel(DiseaseManagement diseaseManagement) throws IOException {
        PageHelper.orderBy("create_time" + " " + "DESC");
        LinkedHashMap<String, List<List<String>>> dataMap = new LinkedHashMap<>();
        List<List<String>> listData1 = new ArrayList<>();
        Workbook wb = null;
        List<DiseaseManagement> dmList =baseMapper.queryList(diseaseManagement);
        List<String> list0 = new ArrayList<>();
        list0.add("地块名称");
        list0.add("发生时间");

        list0.add("病害名称");


        listData1.add(list0);
        if (dmList != null && dmList.size() > 0) {
            for (int i = 0; i < dmList.size(); i++) {
                DiseaseManagement dism = dmList.get(i);
                List<String> list = new ArrayList<>();

                list.add(dism.getLandName());
                list.add(dism.getDtime());
                list.add(dism.getInformation());

                listData1.add(list);
            }
        }
        dataMap.put("病情信息", listData1);
        ExcelUtil excelUtil = new ExcelUtil();
        wb = excelUtil.writeExcel(dataMap, "病情信息");
        return wb;
    }
    //病情管理详情
    @Override
    public Workbook exportExcel2(DiseaseManagement diseaseManagement) throws IOException {
        PageHelper.orderBy("create_time" + " " + "DESC");
        LinkedHashMap<String, List<List<String>>> dataMap = new LinkedHashMap<>();
        List<List<String>> listData1 = new ArrayList<>();
        Workbook wb = null;
        List<DiseaseManagement> dmList =baseMapper.queryDMList(diseaseManagement);
        List<String> list0 = new ArrayList<>();

        list0.add("地块名称");
        list0.add("发生时间");
        list0.add("情况说明");
        list0.add("状态");

        listData1.add(list0);
        if (dmList != null && dmList.size() > 0) {
            for (int i = 0; i < dmList.size(); i++) {
                DiseaseManagement dism = dmList.get(i);
                List<String> list = new ArrayList<>();
                list.add(dism.getLandName());
                list.add(dism.getDtime());
                list.add(dism.getInformation());
                list.add(dism.getDtype());

                listData1.add(list);
            }
        }
        dataMap.put("病情管理信息", listData1);
        ExcelUtil excelUtil = new ExcelUtil();
        wb = excelUtil.writeExcel(dataMap, "病情管理信息");
        return wb;
    }

    //病情管理
    @Override
    public Workbook exportExcel3(DiseaseManagement diseaseManagement) throws IOException {
        PageHelper.orderBy("create_time" + " " + "DESC");
        LinkedHashMap<String, List<List<String>>> dataMap = new LinkedHashMap<>();
        List<List<String>> listData1 = new ArrayList<>();
        Workbook wb = null;
        List<DiseaseManagement> dmList =baseMapper.queryDMList(diseaseManagement);
        List<String> list0 = new ArrayList<>();
        list0.add("名字");
        list0.add("数据");

        list0.add("状态");


        listData1.add(list0);
        if (dmList != null && dmList.size() > 0) {
            for (int i = 0; i < dmList.size(); i++) {
                DiseaseManagement dism = dmList.get(i);
                List<String> list = new ArrayList<>();

                list.add(dism.getInformation());
                list.add(dism.getDnum());
                list.add(dism.getDtype());

                listData1.add(list);
            }
        }
        dataMap.put("病情管理信息", listData1);
        ExcelUtil excelUtil = new ExcelUtil();
        wb = excelUtil.writeExcel(dataMap, "病情管理信息");
        return wb;
    }


    //月分析
    @Override
    public List<DiseaseManagement> queryMonthList(DiseaseManagement diseaseManagement) {
        return baseMapper.queryMonthList(diseaseManagement);
    }

    //月分析
    @Override
    public List<DiseaseManagement> queryMonthListGroup(DiseaseManagement diseaseManagement) {
        return baseMapper.queryMonthListGroup(diseaseManagement);
    }

     //月分析
    @Override
    public List<DiseaseManagement> queryMList(DiseaseManagement diseaseManagement) {
        return baseMapper.queryMList(diseaseManagement);
    }

    //月分析导出
    @Override
    public Workbook exportExcelMonth(DiseaseManagement diseaseManagement) throws IOException {
        PageHelper.orderBy("create_time" + " " + "DESC");
        LinkedHashMap<String, List<List<String>>> dataMap = new LinkedHashMap<>();
        List<List<String>> listData1 = new ArrayList<>();
        Workbook wb = null;
        List<DiseaseManagement> dmList =baseMapper.queryMList(diseaseManagement);
        List<String> list0 = new ArrayList<>();
        list0.add("状态");
        list0.add("数据");

        list0.add("发生时间");


        listData1.add(list0);
        if (dmList != null && dmList.size() > 0) {
            for (int i = 0; i < dmList.size(); i++) {
                DiseaseManagement dism = dmList.get(i);
                List<String> list = new ArrayList<>();

                list.add(dism.getDtype());
                list.add(dism.getDnum());
                list.add(new SimpleDateFormat("yyyy-MM-dd").format(dism.getCreateTime()));

                listData1.add(list);
            }
        }
        dataMap.put("病情月分析", listData1);
        ExcelUtil excelUtil = new ExcelUtil();
        wb = excelUtil.writeExcel(dataMap, "病情月分析");
        return wb;
    }



    //年分析
    @Override
    public List<DiseaseManagement> queryYearList(DiseaseManagement diseaseManagement) {
        return baseMapper.queryYearList(diseaseManagement);
    }
    //年分析
    @Override
    public List<DiseaseManagement> queryYearListGroup(DiseaseManagement diseaseManagement) {
        return baseMapper.queryYearListGroup(diseaseManagement);
    }

    //年分析
    @Override
    public List<DiseaseManagement> queryYList(DiseaseManagement diseaseManagement) {
        return baseMapper.queryYList(diseaseManagement);
    }


     //年分析
    @Override
    public List<DiseaseManagement> queryListThree( ) {
        return baseMapper.queryListThree();
    }


    //年分析导出
    @Override
    public Workbook exportExcelYear(DiseaseManagement diseaseManagement) throws IOException {
        PageHelper.orderBy("create_time" + " " + "DESC");
        LinkedHashMap<String, List<List<String>>> dataMap = new LinkedHashMap<>();
        List<List<String>> listData1 = new ArrayList<>();
        Workbook wb = null;
        List<DiseaseManagement> dmList =baseMapper.queryYList(diseaseManagement);
        List<String> list0 = new ArrayList<>();
        list0.add("状态");
        list0.add("数据");

        list0.add("发生时间");


        listData1.add(list0);
        if (dmList != null && dmList.size() > 0) {
            for (int i = 0; i < dmList.size(); i++) {
                DiseaseManagement dism = dmList.get(i);
                List<String> list = new ArrayList<>();

                list.add(dism.getDtype());
                list.add(dism.getDnum());
                list.add(dism.getDyear());

                listData1.add(list);
            }
        }
        dataMap.put("病情年分析", listData1);
        ExcelUtil excelUtil = new ExcelUtil();
        wb = excelUtil.writeExcel(dataMap, "病情年分析");
        return wb;
    }


}
